package main.bots;
import java.util.Random;

import main.client;


public class Talking implements Runnable {
	private static Thread thread;
	private static client client;
	private static Talking talk = null;
	public boolean botRunning = true;
	private Random rand = new Random();
	private static String autoText = "";
	public static Talking getTalk(client c, String message) {
		System.out.println("AutoTalk loading.....");
		client = c;
		c.botting = true;
		autoText = message;
		if(talk == null) {
			System.out.println("Creating AutoTalk thread..");
			talk = new Talking();
			thread = new Thread(talk);
			thread.start();
		}
		return talk;
	}

	@Override
	public void run() {
		System.out.println("AutoTalk Thread Started: " + Thread.currentThread().getName());
		while(botRunning) {
			if(client == null || client.stream == null) { //something went wrong
				System.out.println("client || stream  was null");	
				return;
			}
			client.chatMessage(autoText);
			try {
				int i = rand.nextInt(6000);
				System.out.println("Random sleep time set at: " + i);
				Thread.sleep(i);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				botRunning = false;
			}
		}
		
	}

}
